<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="author" content="wangbo">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <ul id="caidan">
  </ul>
  <input id="input" type="text"><button id="add">添加菜单</button>
  <script>
    let add = document.querySelector("#add")
    add.addEventListener("click", function () {
      let ul = document.getElementById('caidan')
      let li = document.createElement("li")
      let val = document.querySelector("#input").value
      let li_val = document.createTextNode(val)
      let btn = document.createElement("button")
      let btn_text = document.createTextNode("删除")
      btn.appendChild(btn_text)
      btn.addEventListener("click", function (e) {
        e.target.parentNode.remove()
      })
      li.appendChild(li_val)
      li.appendChild(btn)
      ul.appendChild(li)
      document.querySelector("#input").value=""
    })


  </script>
</body>

</html>